from fastapi import (
    APIRouter, Request, Depends
)
from fastapi_limiter.depends import RateLimiter

from common.result import Success
from common.redis import redis_client
from common.log import log
from common.exception.errors import CustomException
from common.response.response_code import HttpCode

from config.base import get_settings

settings = get_settings()

router = APIRouter()

@router.get('/test', summary="测试接口")
async def union_test():
    """测试接口
    """
    log.info("测试接口")

    return Success()

@router.get(
    '/test_limiter',
    summary="测试接口频率",
    dependencies=[Depends(RateLimiter(times=5, seconds=10))])
async def union_test_limiter(request: Request):
    """测试接口频率
    """
    if settings.app.ENABLE_LIMITER and settings.redis.ENABLED:
        raise CustomException(
            code=HttpCode.HTTP_500,
            msg="未启用 limiter 或 redis"
        )
    log.info("测试接口频率")
    return Success()
    